home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Mops 2.7 / Mops source / More classes / MW documents / MWdocs < prev    next >
Encoding:
Text File  |  1991-06-18  |  6.1 KB  |  276 lines  |  [TEXT/MSET]

  1. \ Microsoft Word 4.0 documents
  2. \ Access to Microsoft Word documents.        MRH Oct 86
  3. \ March 87 - extensively revised.  Input of formats implemented.
  4. \ April 87 - handling of MW 3.0 docs included
  5. \    - package broken into several files.
  6. \ March 88 - Reorganized into modules.
  7.  
  8. need    byteString
  9. need    stringarray
  10. need    file+
  11. need    info_run
  12.  
  13.  
  14. \ The following items are used by the application.
  15.  
  16. 'type WDBN  constant    MWDOC_TYPE
  17. 'type WORD  constant    MW1_CREATOR
  18. 'type MSWD  constant    MW3_CREATOR
  19.  
  20.  
  21. false    value    TEXT_ONLY?    \ Set this TRUE if you only want text
  22.                 \  in or out.
  23. false    value    FACING_PAGES?
  24.  
  25.  
  26. \ The application must set up these strings.  This package puts
  27. \ info into them or takes it from them, as the case may be.
  28.  
  29. info_run    FMT_RUN
  30. info_run    PARA_RUN
  31.  
  32. 14 setInfoSize: fmt_run
  33.  2 setInfoSize: para_run
  34.  
  35.  
  36. bytestring    TEXT        \ Ascii text of the document
  37. bytestring    STYLE_NAMES    \ Style names
  38.  
  39.  
  40. \        =================================
  41.  
  42. \              Constants, values etc.
  43.  
  44. \        =================================
  45.  
  46. type{    MWtext  MW1  MW3  MW4  }    \ Add more as necessary!!
  47.  
  48.     0    value    MWTYPE            \ Type of current document
  49.  
  50.  
  51.     3    constant    DFLT_FONT#    \ We use Geneva as the default font
  52. $ 100    constant    HDR_LEN        \ For Word 3 - redefined in MW1mod
  53.  
  54. $  C    constant    SECT        \ Code for a section break
  55.  
  56. $  F    constant    FTN_MARK    \ Footnote mark
  57. $ 16    constant    HF_END_MARK    \ Only in text proper
  58. $ 17    constant    SECT_END_MARK    \ NOT in text proper - HF area only
  59. $ 18    constant    TEXT_END_MARK    \ We mark the end of the text proper
  60.                     \ with this.  We hope the user
  61.                     \ doesn't put any $18s in!!
  62.  
  63. \ We also use: 10 even header  11 odd header  12 even footer  13 odd footer
  64. \ 14 first header  15 first footer.
  65.  
  66. objPtr    TheFCB    class_is file+
  67.  
  68.     0    value    #STYLES        \ Number of styles in style sheet.
  69.     0    value    MEM_NEEDED
  70.     0    value    BLK#
  71.     0    value    #ENTRIES
  72.     0    value    #BLKS
  73.     0    value    #FMT_BLKS
  74.     0    value    #PARA_BLKS
  75.     0    value    #LEVELS
  76.     0    value     SAVE_OFFS
  77.     0    value    PARA_OFFS
  78.     0    value    REAL_TEXT_LEN
  79.     0    value    FTN_LEN
  80.     0    value    TOTAL_TEXT_LEN
  81.     0    value    TEXT&HF_LEN
  82.     0    value    #INSRTD
  83.     0    value    UNMPD_OLD
  84.     0    value    UNMPD_NEW
  85. false    value    FAST?
  86. false    value    GHF?
  87. false    value    MW4?        \ True if this is a Word 4 document
  88.  
  89. false    value    WRONGTYPE?
  90. false    value    MYSTERY?
  91.     0    value    UNPROCESSED_CODE
  92.  
  93.  
  94. bytestring    BUF
  95. bytestring    BUF_TMP
  96. bytestring    BUF_OFFSETS
  97. bytestring    HF_OFFSETS    \ String of offsets of hdrs and footers
  98. bytestring    SECT_OFFSETS    \ String of section offset info
  99. bytestring    SECT_STR    \ String of strange section info
  100. bytestring    FTN_MARKERS    \ String of footnote marker offsets in text
  101. bytestring    FTN_OFFSETS    \ String of offsets to the footnotes
  102. info_run    SRC        \ Temp substring for sundry sources
  103. info_run    DST        \ Likewise for destinations
  104. bytestring    TMP        \ Used for many things
  105.  
  106. bytestring    TheFile        \ Holds input MW3/4 doc before fixup
  107.  
  108. bytestring    FMT_BLK#S
  109. bytestring    PARA_BLK#S
  110. bytestring    BLK#S
  111. bytestring    PARA_TMP
  112.  
  113. bytestring    CHANGES        \ These 5 strings are used in handling
  114. bytestring    FMT_OV_STR    \  "Fast Saved" documents.
  115. bytestring    PARA_OV_STR
  116. bytestring    SECT_OV_STR
  117. info_run    FMT_OV_RUN
  118.  
  119. infoSize: fmt_run  setInfoSize: fmt_ov_run
  120.  
  121. 4 stringarray    HF_ARRAY    \ Used in handling headers and footers
  122.  
  123. 10 constant    FMT_LEN
  124.  
  125. variable    FMT    fmt_len 4 +  allot    \ Allow a safety margin
  126.  
  127. trtbl        UTTBL        \ Utility translate table - various uses
  128.  
  129.  
  130. \        ========== Imports ==========
  131.  
  132. forward    STR_OUT
  133.  
  134. from MWUTMOD    import{  TRIM_FMT_RUN ?KEEP_PARA NEXT_PARA TRIM_PARA_RUN  }
  135.  
  136. from MW1MOD    import{  SETUP_INP1  INPUT_FILE1  WINDUP_INP1  SEND1  }
  137.  
  138. from G&HFMOD    import{  MARK_SP  SPEC_IN  MARK_FTN
  139.             MARK_HFS  UPDATE_HFS  FIXUP_FTN  FIXUP_HFS
  140.             HANDLE_SPEC  GHF_FORMATS_OUT  }
  141.  
  142. from MW3/4MOD    import{  GET_STYLE_NAME  GET_STYLE#  NEED_LEVEL  (STR_OUT)
  143.             SETUP_INP3    SETUP_INP4
  144.             INPUT_FILE3    INPUT_FILE4
  145.             FIXIT3        FIXIT4
  146.             WINDUP_INP3    WINDUP_INP4
  147.             SEND3            }
  148.  
  149. :f STR_OUT    (str_out)  ;f
  150.  
  151. \        =============================
  152.  
  153. :class  MWDOC    super(  object  )
  154.  
  155. int    TEXT?
  156. int    CONTINUE?
  157.  
  158. :m CHK_MEM:
  159.     mem_needed  10000 +  free >
  160.     IF  ( short of mem )
  161.         mem_needed  1000 +
  162.         freeBlk                \ purges mem
  163.         >                \ Out of mem?
  164.         IF                \ Aarrggghh!  Yes!
  165.             close: theFcb  drop
  166.             noMem
  167.             false  put: continue?
  168.         THEN
  169.     THEN   ;m
  170.  
  171.  
  172. :m BRING:    \ ( fcb -- )
  173.     -> theFcb   pause
  174.     0 -> #levels  clear: text?
  175.     clear: text  clear: fmt_run  clear: para_run
  176.     clear: style_names
  177.     getFileInfo: theFcb  OK?
  178.     size: theFcb  -> mem_needed
  179.     true  put: continue?
  180.     getType: theFcb  'type TEXT  =
  181.     IF
  182.         MWtext -> MWtype
  183.     ELSE
  184.         false -> mw4?
  185.         getCreator: theFcb  MW1_creator  =
  186.         IF
  187.             MW1
  188.         ELSE
  189.             pad 2  read: theFcb  OK?
  190.             pad w@
  191.             CASE[    $ FE34    ]=>    MW3
  192.                 [    $ FE37    ]=>    MW4  true -> mw4?
  193.                   DEFAULT=>    true -> wrongType?  MWtext
  194.             ]CASE
  195.         THEN
  196.         -> MWtype
  197.     THEN
  198.     MWtype
  199.     SELECT{
  200.     MWtext    IS{
  201.             true  put: text?
  202.             chk_mem: self   get: continue?
  203.             IF
  204.                 theFcb  readAll: text
  205.             THEN                    }END
  206.  
  207.     MW1    IS{    setup_inp1
  208.             chk_mem: self  get: continue?
  209.             IF  input_file1  THEN            }END
  210.  
  211.     MW3    IS{    setup_inp3
  212.             chk_mem: self  get: continue?
  213.             IF  input_file3  THEN            }END
  214.  
  215.     MW4    IS{    setup_inp4
  216.             chk_mem: self  get: continue?
  217.             IF  input_file4  THEN            }END
  218.         default{
  219.     }SELECT  ;m
  220.  
  221.  
  222.  
  223. :m FIXUP:  { flg -- flg' }
  224.         \ Fixes up everything after reading the
  225.         \ file in.  flg is true if the caller wants us to continue.
  226.         \ We do things this way as when we read in the file we
  227.         \ opened all sorts of strings which need to be released
  228.         \ even if the input operation is to be aborted.  We return
  229.         \ flg' which is true if everything is OK.
  230.  
  231.     pause
  232.     get: text?  IF  true  EXIT  THEN
  233. \    watchcurs
  234.     get: continue?  flg and  dup  ( do we continue? )
  235.     MWtype
  236.     SELECT{
  237.         MWtext    IS{                    }END
  238.         MW1    IS{    drop                }END
  239.         MW3    IS{    IF  fixit3  THEN  windup_inp3    }END
  240.         MW4    IS{    IF  fixit4  THEN  windup_inp4    }END
  241.  
  242.         default{
  243.     }SELECT
  244. \    arrowcurs
  245.     pause  ;m
  246.  
  247.  
  248. :m SEND:  { fcb -- }
  249.     pause
  250.     false -> mw4?        \ We're not writing in MW4 format yet
  251.     text_only?
  252.     IF
  253.         reset: text  text_end_mark  chsearch: text  drop
  254.         len: text  setsize: text
  255.         fcb  $write: text   EXIT
  256.     THEN
  257.     fcb getFileInfo: file+  OK?  fcb getCreator: file+
  258.     MW1_creator =  IF  MW1  ELSE  MW3  THEN
  259.     -> MWtype
  260.     fcb
  261.     MWtype
  262.     SELECT{
  263.     MW1    IS{    send1    }END
  264.     MW3    IS{    send3    }END
  265.         default{
  266.     }SELECT  ;m
  267.  
  268. ;class
  269.  
  270. MWdoc  TheDoc
  271.  
  272. compile: MWutMod
  273. compile: MW1mod
  274. compile: g&hfMod
  275. compile: MW3/4mod
  276.